package ee.homework.sixth;

public class TransitiveClosure {

	public static void main(String[] args) {
		TransitiveClosure tc = new TransitiveClosure();
		tc.run();
	}

	public void run() {
		int[][] matrix = new int[][] { 
				{ 0, 1, 0, 0, 0 }, 
				{ 0, 0, 0, 0, 1 },
				{ 0, 1, 0, 1, 0 }, 
				{ 1, 0, 0, 0, 0 }, 
				{ 0, 0, 0, 1, 0 } 
			};

		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix.length; j++) {
				if (matrix[j][i] == 1) {
					for (int k = 0; k < matrix.length; k++) {
						if (matrix[i][k] == 1) {
							matrix[j][k] = 1;
						}
					}
				}
			}
		}

		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix.length; j++) {
				System.out.print(matrix[i][j] + " ");
			}
			System.out.println();
		}
	}
}
